package com.stx.stcp.controller;

import com.github.pagehelper.PageInfo;
import com.stx.stcp.bean.MenuBean;
import com.stx.stcp.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class MenuController {

    @Autowired
    private MenuService menuService;

    @RequestMapping("pri/back/menuinsert")
    public String insert(HttpServletRequest request, MenuBean menuBean){
        menuService.insert(request,menuBean);
        return "back/menu_add";
    }

    @RequestMapping("pri/back/menulist")
    public String menuList(Model model, @RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum){
        List list=menuService.menuList(pageNum);
        PageInfo<MenuBean> pageInfo=new PageInfo<MenuBean>(list);
        model.addAttribute("pageInfo",pageInfo);
        return "back/menu_list";
    }

    @RequestMapping("pri/back/selectbyid")
    public String selectById(int id,Model model){
        MenuBean menuBean = menuService.selectById(id);
        model.addAttribute("menu",menuBean);
        return "back/menu_edit";
    }

    @RequestMapping("pri/back/menuedit")
    public String update(MenuBean menuBean,HttpServletRequest request){
        menuService.update(menuBean,request);
        return "redirect:/pri/back/menulist";

    }
}
